package com.framewiki.gpt.web.controller;

import com.cdkjframework.util.tool.CopyUtils;
import com.framewiki.gpt.dto.request.CreateChatCompletionDto;
import com.framewiki.gpt.dto.request.CreateChatCompletionVo;
import com.framewiki.gpt.dto.response.ChatCompletionResponseDto;
import com.framewiki.gpt.dto.response.ChatCompletionResponseVo;
import com.framewiki.gpt.service.ChatService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ProjectName: framewiki-gpt
 * @Package: com.framewiki.gpt.web.controller
 * @ClassName: ChatController
 * @Description: java类作用描述
 * @Author: xiaLin
 * @Date: 2023/6/16 23:23
 * @Version: 1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/chat")
public class ChatController {

  /**
   * 聊天服务
   */
  private final ChatService chatServiceImpl;

  /**
   * 创建对话
   *
   * @param content 内容
   */
  @ResponseBody
  @PostMapping(value = "/create/completion")
  public ChatCompletionResponseVo createChatCompletion(@RequestBody @Validated CreateChatCompletionVo content) {
    // 数据转换
    CreateChatCompletionDto completionDto = CopyUtils.copyNoNullProperties(content, CreateChatCompletionDto.class);
    // 请求聊天内容
    ChatCompletionResponseDto responseDto = chatServiceImpl.createChatCompletion(completionDto);

    // 返回结果
    return CopyUtils.copyNoNullProperties(responseDto, ChatCompletionResponseVo.class);
  }
}
